// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   HomeRedirectController.java

package com.nervytech.tutorcruise.spring.controller;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.nervytech.tutorcruise.db.enums.UserTypeEnum;
import com.nervytech.tutorcruise.spring.security.auth.SessionUser;
import com.nervytech.tutorcruise.spring.security.auth.UserDetailsServiceImpl;

@Controller
@RequestMapping("/home/redirect")
public class HomeRedirectController {

	@RequestMapping(method = RequestMethod.GET)
	public String redirectUser(HttpServletRequest request) {
		SessionUser user = UserDetailsServiceImpl.currentUserDetails();
		System.out.println("Inside Show Profileeeeeeeeeeeeeeeeeeee");
		if (request.isUserInRole(UserTypeEnum.DEFAULT.name())) {
			System.out.println("Redirecting HEREEEEEEEEEEEEEEEEEEEEEEEEEE");
			return "redirect:/newusr/firstlogin";
		} else {
			return "redirect:/usr/profile";
		}
	}

	private boolean isFirstTimeUser(Collection collection) {
		boolean isFirstTimeuser = false;
		List userRoles = collectionToList(collection);
		GrantedAuthority gau = (GrantedAuthority) userRoles.get(0);
		String userType = gau.getAuthority();
		System.out.println((new StringBuilder(
				"User Type is =================>>>>>> ")).append(userType)
				.toString());
		if (userType.equalsIgnoreCase(UserTypeEnum.DEFAULT.name()))
			isFirstTimeuser = true;
		System.out.println((new StringBuilder(
				"Is First Time USERRRRRRRRRRRRRR ")).append(isFirstTimeuser)
				.toString());
		return isFirstTimeuser;
	}

	public List collectionToList(Collection collection) {
		List list;
		if (collection instanceof List)
			list = (List) collection;
		else
			list = new ArrayList(collection);
		return list;
	}
}
